//记忆化搜索，错误解法！！！！（因为虽是有向图但是存在环）
#include <iostream>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int e[N], ne[N], h[N], idx;

int m[N];

int n, z;

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

int dfs(int u)
{
	if (m[u] != -1) return m[u];
	
	m[u] = u;
	int maxv = u;
	
	for (int i = h[u]; ~i; i = ne[i])
	{
		int j = e[i];
		maxv = max(maxv, dfs(j));
	}
	
	return m[u] = maxv;
}

int main()
{
	scanf("%d%d", &n, &z);
	
	memset(m, -1, sizeof m);
	memset(h, -1, sizeof h);
	
	for (int i = 0; i < z; i ++ )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		
		add(a, b);
	}
	
// 	exit(0);
	
	for (int i = 1; i <= n; i ++ )
	{
		m[i] = dfs(i);
        printf("%d ",m[i]);
	}
	
	return 0;
}


//------------------------
//反向建边+dfs
#include <iostream>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int h[N], ne[N], e[N], idx;

int r[N];

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

void dfs(int u, int p)
{
	if (r[u]) return;
	r[u] = p;
	
	for (int i = h[u]; ~i; i = ne[i])
	{
		int j = e[i];
		dfs(j, p);
	}
}

int main()
{
	int n, m;
	
	cin >> n >> m;
	
	memset(h, -1, sizeof h);
	
	for (int i = 0; i < m; i ++ )
	{
		int a, b;
		cin >> a >> b;
		
		add(b, a);
	}
	
	for (int i = n; i > 0; i -- ) dfs(i, i);
	
	for (int i = 1; i <= n; i ++ ) cout << r[i] << ' ';
	
	return 0;
	
}